{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  <center>选股分析</center>\n",
    "<center>第二小组</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Section 2 机器学习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 特征工程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Jimei\\Anaconda3\\lib\\importlib\\__init__.py:126: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  return _bootstrap._gcd_import(name[level:], package, level)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataview loaded successfully.\n"
     ]
    }
   ],
   "source": [
    "from jaqs_fxdayu.data import DataView # 可以视为一个轻量级的数据库，数据格式基于pandas，方便数据的调用和处理\n",
    "import os\n",
    "import warnings\n",
    "\n",
    "\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "dataview_folder = r'C:/Users/Jimei/Desktop'\n",
    "dv = DataView()\n",
    "dv.load_dataview(dataview_folder)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "alpha191"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha2=dv.add_formula('alpha2','(-1*Delta((((close-low)-(high-close))/(high-low)),1))',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha3=dv.add_formula('alpha3',\"Ts_Sum(If((close==Delay(close,%s)),0,close-(If((close>Delay(close,%s)),Min(low,Delay(close,%s)),Max(high,Delay(close,%s))))),%s)\"%(1,1,1,1,6),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha4=dv.add_formula('alpha4',\"(If(((Ts_Sum(close,8)/8) + StdDev(close, 8))<(Ts_Sum(close,2)/2),(-1*1),If((Ts_Sum(close,2)/2)<((Ts_Sum(close,8)/8)-StdDev(close,8)),1,If((((volume/Ts_Mean(volume,20)>1))|| ((volume /Ts_Mean(volume,20)) == 1)), 1 , (-1 * 1)))))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha5=dv.add_formula('alpha5','(-1*(Ts_Max(Correlation(Ts_Rank(volume,5),Ts_Rank(high,5),5),3)))',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha6=dv.add_formula('alpha6',\"Rank(Sign(Delta((open * 0.85) + (high * 0.15), 4)*-1))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha7=dv.add_formula('alpha7',\"((Rank(Ts_Max((vwap - close), 3)) + Rank(Ts_Min((vwap - close), 3))) * Rank(Delta(volume, 3)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha8=dv.add_formula('alpha8',\"Rank(Delta(((((high + low) / 2) * 0.2) + (vwap * 0.8)), 4) * -1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha9=dv.add_formula('alpha9',\"Sma(((high+low)/2-(Delay(high,%s)+Delay(low,%s))/2)*(high-low)/volume,%s,%s)\"%(1,1,7,2),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha10=dv.add_formula('alpha10',\"Rank(Ts_Max(If(Return(close,1)<0,StdDev(Return(close,1),20),close)^2,5))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha11=dv.add_formula('alpha11',\"Ts_Sum(((close-low) - (high-close)) / (high-low) * volume,6)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha12=dv.add_formula('alpha12','(Rank((open- (Ts_Sum(vwap, %d) / %d)))) * (-1 * (Rank(Abs(close - vwap))))'%(10,10),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha13 = dv.add_formula('alpha13',\"(high*low)^0.5-vwap\", is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha14 = dv.add_formula('alpha14', 'close-Delay(close,5)', is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha15 = dv.add_formula('alpha15', \"open/Delay(close,1)-1\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha16 = dv.add_formula(\"alpha16\",\"(-1*Ts_Max(Rank(Correlation(Rank(volume),Rank(vwap),5)),5))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha17 = dv.add_formula('alpha17', \"Rank((vwap - Ts_Max(vwap, 15)))^Delta(close, 5)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha18=dv.add_formula('alpha18',\"close/Delay(close,5)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha19=dv.add_formula('alpha19',\"If((close >= Delay(close,5),(close-Delay(close,5))/close),(close-Delay(close,5))/Delay(close,5))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha20 = dv.add_formula('alpha20',\"(close-Delay(close,6))/Delay(close,6)*100\",\n",
    "                             is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "dv.add_formula('Mean','Ts_Mean(close,6)',is_quarterly = False, add_data = True)\n",
    "alpha21 = dv.add_formula('alpha21',\"Ta('LINEARREG_SLOPE',0,Mean,Mean,Mean,Mean,Mean,6)\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha22 = dv.add_formula('alpha22','Sma(((close-Ts_Mean(close,6))/Ts_Mean(close,6)-Delay((close-Ts_Mean(close,6))/Ts_Mean(close,6),3)),12,1)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha23=dv.add_formula('alpha23',\"Sma(If(close>Delay(close,1),StdDev(close,20),0),20,1)/(Sma(If(close>Delay(close,1),StdDev(close,20),0),20,1)+Sma(If(close<=Delay(close,1),StdDev(close,20),0),20,1))*100\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha24=dv.add_formula('alpha24',\"Sma(close-Delay(close,5),5,1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha25=dv.add_formula('alpha25', '((-1 * Rank((Delta(close, 7) * (1 - Rank(Decay_linear((volume / Ts_Mean(volume,20)), 9)))))) * (1+Rank(Ts_Sum(close/Delay(close,1)-1, 250))))', is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha26 = dv.add_formula('alpha26',\"((((Ts_Sum(close, 7) / 7) - close)) + ((Correlation(vwap, Delay(close, 5), 230))))\",is_quarterly=False,add_data=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha27 = dv.add_formula(\"alpha27\",\"Ta('WMA',0,0,0,0,(close_adj-Delay(close_adj,3))/Delay(close_adj,3)*100+(close_adj-Delay(close_adj,6))/Delay(close_adj,6)*100,0,12)\",\n",
    "           is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha28 = dv.add_formula('alpha28',\"3*Sma((close-Ts_Min(low,9))/(Ts_Max(high,9)-Ts_Min(low,9))*100,3,1)-2*Sma(Sma((close-Ts_Min(low,9))/(Max(high,9)-Ts_Max(low,9))*100,3,1),3,1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha29 = dv.add_formula('alpha29',\"(close-Delay(close,6))/Delay(close,6)*volume\" \n",
    "                             , is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha31 = dv.add_formula(\"alpha31\",\"(close-Ts_Mean(close,12))/Ts_Mean(close,12)*100\",\n",
    "                           is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha32 = dv.add_formula('alpha32',\"(-1 * Ts_Sum(Rank(Corr(Rank(high), Rank(volume), 3)), 3))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha33=dv.add_formula('alpha33',\"((((-1*Ts_Min(low,5))+Delay(Ts_Min(low,5),5))*Rank(((Ts_Sum(Return(close,1),240)-Ts_Sum(Return(close,1),20))/220)))*Ts_Rank(volume,5))\",is_quarterly=False,add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha34= dv.add_formula('alpha34', \"Ts_Mean(close_adj,12)/close_adj\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha35 = dv.add_formula('alpha35',\"(Min(Rank(Decay_linear(Delta(open, 1), 15)), Rank(Decay_linear(Corr((volume), ((open * 0.65) +(open *0.35)),17),7))) * -1)\" ,is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha36 = dv.add_formula('alpha36', \"Rank(Ts_Sum(Correlation(Rank(volume),Rank(vwap),6),2))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha37=dv.add_formula('alpha37',\"(-Rank(((Ts_Sum(open, 5) * Ts_Sum((close/Delay(close,1) - 1), 5)) - Delay((Ts_Sum(open, 5) * Ts_Sum((close/Delay(close,1) - 1), 5)), 10))))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha38 = dv.add_formula('alpha38',\"If(((Ts_Sum(high, 20) / 20) < high) , (-1 * Delta(high, 2)) , 0)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha39 = dv.add_formula('alpha39',\"((Rank(Decay_linear(Delta((close), 2),8)) - Rank(Decay_linear(Correlation(((vwap * 0.3) + (open * 0.7)),Ts_Sum(Ts_Mean(volume,180), 37), 14), 12))) * -1)\",is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha40 = dv.add_formula('alpha40', \"Ts_Sum((If(close>Delay(close,1),volume,0)),26)/Ts_Sum((If(close<=Delay(close,1),volume,0)),26)*100\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha41=dv.add_formula('alpha41','(Rank(Max(Delta((vwap), 3), 5))* -1)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha42 = dv.add_formula('alpha42', \"((-1*Rank(StdDev(high,10)))*Correlation(high,volume,10))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha43 = dv.add_formula(\"alpha43\", \"Ts_Sum(If(close>Delay(close,1),volume,If(close<Delay(close,1),-volume,0)),6)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha44 = dv.add_formula(\"alpha44\",\"Ts_Rank(Decay_linear(Correlation(((low)),Ts_Mean(volume,10),7),6),4)+Ts_Rank(Decay_linear(Delta((vwap),3),10),15)\",is_quarterly=False,add_data = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha45 = dv.add_formula('alpha45', 'Rank(Delta(((close*0.6)+(open*0.4)),1)) * Rank(Correlation(vwap, Ts_Mean(volume,150), 15))', is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha46 = dv.add_formula('alpha46',\"(Ts_Mean(close,3)+Ts_Mean(close,6)+Ts_Mean(close,12)+Ts_Mean(close,24))/(4*close)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha47 = dv.add_formula('alpha47',\"Sma((Ts_Max(high,6)-close)/(Ts_Max(high,6)-Ts_Min(low,6)) * 100,9,1)\" ,is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha48 = dv.add_formula('alpha48',\"(-1*((Rank(((Sign((close - Delay(close, 1))) + Sign((Delay(close, 1) - Delay(close, 2)))) +Sign((Delay(close, 2) - Delay(close, 3)))))) * Ts_Sum(volume, 5)) / Ts_Sum(volume, 20))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha49 = dv.add_formula('alpha49', \"Ts_Sum(If(((high+low)>=(Delay(high,1)+Delay(low,1))),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))),12)/(Ts_Sum(If(((high+low)>=(Delay(high,1)+Delay(low,1))),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))),12)+Ts_Sum(If(((high+low)<=(Delay(high,1)+Delay(low,1))),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))),12))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = dv.add_formula('A',\"Ts_Sum((If((high+low)<=(Delay(high,1)+Delay(low,1)),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1))))),12)\",is_quarterly=False,add_data=True)\n",
    "B = dv.add_formula('B',\"Ts_Sum((If((high+low)>=(Delay(high,1)+Delay(low,1)),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1))))),12)\",is_quarterly=False,add_data=True)\n",
    "alpha50 = dv.add_formula('alpha50',\"(A/(A+B))-(B/(A+B))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha51 = dv.add_formula('alpha51','''Ts_Sum(If((high+low)<=(Delay(high,1)+Delay(low, 1)),0, Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))), 12)/(Ts_Sum(If((high+low)<=(Delay(high,1)+Delay(low,1)),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))),12)+Ts_Sum(If((high+low)>=(Delay(high,1)+Delay(low,1)),0,Max(Abs(high-Delay(high,1)),Abs(low-Delay(low,1)))),12))''',\n",
    "                         is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha52 = dv.add_formula('alpha52', 'Ts_Sum(Max(0,high-Delay((high+low+close)/3,1)),26)/Ts_Sum(Max(0,Delay((high+low+close)/3,1)-low),26)*100',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha53 = dv.add_formula('alpha53',\"Sqrt(CountNans(close>Delay(close,1),12)/12*100)\"\n",
    "                   , is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha54=dv.add_formula('alpha54',\"(-1 * Rank((StdDev(Abs(close-open),5) + (close-open)) + Corr(close, open,10)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha55 = dv.add_formula('alpha55', 'Ts_Sum(16*(close-Delay(close,1)+(close-open)/2+Delay(close,1)-Delay(open,1))/(If(Abs(high-Delay(close,1))>Abs(low-Delay(close,1))&&Abs(high-Delay(close,1))>Abs(high-Delay(low,1)),Abs(high-Delay(close,1))+Abs(low-Delay(close,1))/2+Abs(Delay(close,1)-Delay(open,1))/4,If(Abs(low-Delay(close,1))>Abs(high-Delay(low,1))&&Abs(low-Delay(close,1))>Abs(high-Delay(close,1)),Abs(low-Delay(close,1))+Abs(high-Delay(close,1))/2+Abs(Delay(close,1)-Delay(open,1))/4,Abs(high-Delay(low,1))+Abs(Delay(close,1)-Delay(open,1))/4)))*Max(Abs(high-Delay(close,1)),Abs(low-Delay(close,1))),20)',\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha56=dv.add_formula('alpha56',\"(Rank((open-Ts_Min(open, 12)))<Rank((Rank(Corr(Ts_Sum(((high+low)/2),19),Ts_Sum(Ts_Mean(volume,40), 19), 13))^5)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha57 = dv.add_formula('alpha57', \"Ta('SMA',0,0,0,0,close-Ts_Min(low,9)/(Ts_Max(high,9)-Ts_Min(low,9))*100,3,1)\",is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha58=dv.add_formula('alpha58',\"Ts_Sum(If(close>Delay(close,1),1,0),20)/20*100\"\n",
    "                           ,is_quarterly=False,add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha59 = dv.add_formula('alpha59','Ts_Sum(If(close==Delay(close,1),0,close-If(close>Delay(close,1),Min(low,Delay(close,1)),Max(high,Delay(close,1)))),20)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha60 = dv.add_formula('alpha60', \"Ts_Sum(((close-low)-(high-close))/(high-low)*volume,20)\",\n",
    "                             is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha61 = dv.add_formula('alpha61', \"(Max(Rank(Decay_linear(Delta(vwap,1),12)),Rank(Decay_linear(Rank(Corr((low),Ts_Mean(volume,80),8)), 17))) * -1)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha62 = dv.add_formula('alpha62', \"Rank(Decay_linear(Rank(Corr((low),Ts_Mean(volume,80),8)), 17))) * -1)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha63=dv.add_formula('alpha63',\"Sma(Max(close-Delay(close,1),0),6,1)/Sma(Abs(close-Delay(close,1)),6,1)*100\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha64 = dv.add_formula(\"alpha64\",'''(Max(Rank(Decay_linear(Corr(Rank(vwap),Rank(volume),4),4)),Rank(Decay_linear(Max(Corr(Rank(close), Rank(Ts_Mean(volume,60)), 4), 13), 14))) * -1)''',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha65=dv.add_formula('alpha65',\"Ts_Mean(close,6)/close\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha66 = dv.add_formula('alpha66', \"(close-Ts_Mean(close,6))/Ts_Mean(close,6)*100\",\n",
    "                             is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha67 = dv.add_formula('alpha67','Sma(Max(close_adj-Delay(close_adj,1),0),24,1)/Sma(Abs(close_adj-Delay(close_adj,1)),24,1)*100',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha68=dv.add_formula('alpha68','Sma(((high+low)/2-(Delay(high,1)+(Delay(low,1)))/2)*(high-low)/volume,15,2)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "DTM = dv.add_formula('DTM','If(open<=Delay(open, 1), 0, Max((high-open), (open-Delay(open, 1))))',\n",
    "                        is_quarterly=False, add_data=True)\n",
    "DBM = dv.add_formula('DBM','If(open>=Delay(open, 1), 0, Max((open-low), (open-Delay(open, 1))))',\n",
    "                        is_quarterly=False, add_data=True)\n",
    "alpha69 = dv.add_formula('alpha69','If(Ts_Sum(DTM,20)>Ts_Sum(DBM,20), 0,(Ts_Sum(DTM,20)-Ts_Sum(DBM,20))/Ts_Sum(DBM,20))',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha70 = dv.add_formula('alpha70', \"StdDev(turnover,6)\",\n",
    "#         is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha71 = dv.add_formula('alpha71', '(close-Ts_Mean(close, 24))/Ts_Mean(close, 24)*100', is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha72 =dv.add_formula('alpha72',\"Sma((Ts_Max(high,{})-close)/(Ts_Max(high,{})-Ts_Min(low,{}))*{},{},{})\".format(6,6,6,100,15,1),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha73 = dv.add_formula('alpha73',\"-1*(Ts_Rank(Decay_linear(Decay_linear(Correlation(close,volume,10),16),4),5)-Rank(Decay_linear(Correlation(vwap,Ts_Mean(volume,30),4),3)))\",\n",
    "                         is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha74 = dv.add_formula('alpha74','Rank(Correlation(Ts_Sum(((low_adj*0.35)+(vwap_adj*0.65)), 20), Ts_Sum(Ts_Mean(volume,40), 20), 7))+Rank(Correlation(Rank(vwap_adj), Rank(volume), 6))',\n",
    "                             is_quarterly=False, add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha76 = dv.add_formula('alpha76','StdDev(Abs((close_adj/Delay(close_adj,1)-1))/volume,20)/Ts_Mean(Abs((close_adj/Delay(close_adj,1)-1))/volume,20)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "Decay_linear_content1=\"((high+low)/2+high)-(vwap+high)\"\n",
    "Decay_linear_content2=\"Correlation(((high+low)/2),Ts_Mean(volume,40),3)\"\n",
    "\n",
    "Rank1=\"Rank(Decay_linear({},20))\".format(Decay_linear_content1)\n",
    "Rank2=\"Rank(Decay_linear({},6))\".format(Decay_linear_content2)\n",
    "\n",
    "alpha77=dv.add_formula('alpha77','Min({},{})'.format(Rank1,Rank2),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha78=dv.add_formula('alpha78',\"(-((high+low+close)/3-Ts_Mean((high+low+close)/3,12))/(0.015*Ts_Mean(Abs(close-Ts_Mean((high+low+close)/3,12)),12)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "dv.add_formula('a',\"close-Delay(close,1)\",is_quarterly=False, add_data=True)\n",
    "alpha79 = dv.add_formula('alpha79',\"Sma(Max(a,0),12,1)/Sma(Abs(a),12,1)*100\" ,is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha80 = dv.add_formula(\"alpha80\", \"(volume-Delay(volume,5))/Delay(volume,5)*100\"\n",
    "                             , is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha81=dv.add_formula('alpha81','Sma(volume,21,2)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha82 = dv.add_formula('alpha82',\"Sma((Ts_Max(high,6)-close)/(Ts_Max(high,6)-Ts_Min(low,6))*100,20,1)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha83=dv.add_formula('alpha83',\"(-1*Rank(Covariance(Rank(high),Rank(volume),5)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha84 = dv.add_formula('alpha84', \"Ts_Sum(If(close>Delay(close,1),volume,If(close<Delay(close,1),-volume,0)),20)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha85 = dv.add_formula('alpha85',\"(Ts_Rank((volume / Ts_Mean(volume,20)), 20) * Ts_Rank((-1 * Delta(close, 7)), 8))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha86 = dv.add_formula('alpha86', \"If(((((Delay(close, 20) - Delay(close, 10))/10) - ((Delay(close, 10) - close) / 10))>0.25) , (-1) ,(If(((((Delay(close, 20) - Delay(close, 10)) / 10) - ((Delay(close, 10) - close) / 10)) < 0) , 1 ,((-1) *(close - Delay(close, 1))))))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha87 = dv.add_formula('alpha87','((Rank(Decay_linear(Delta(vwap, 4), 7)) + Ts_Rank(Decay_linear(((((low * 0.9) + (low * 0.1)) - vwap) /(open - ((high + low) / 2))), 11), 7)) * -1)'\n",
    "                               , is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha88 = dv.add_formula('alpha88', \"((close-Delay(close,20))/Delay(close,20))*100\"\n",
    "       , is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha89=dv.add_formula('alpha89','2*(Sma(close,13,2)-Sma(close,27,2)-Sma(Sma(close,13,2)-Sma(close,27,2),10,2))',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha90 = dv.add_formula('alpha90',\"( Rank(Corr(Rank(vwap), Rank(volume), 5)) * -1)\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha91 = dv.add_formula('alpha91', \"((Rank((close - Max(close, 5)))*Rank(Correlation((Ts_Mean(volume,40)), low, 5))) * -1)\",is_quarterly=False, add_data=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha92=dv.add_formula('alpha92',\"(Max(Rank(Decay_linear(Delta(((close*0.35)+(vwap*0.65)),2),3)),Ts_Rank(Decay_linear(Abs(Corr((Ts_Mean(volume,180)), close, 13)), 5), 15)) * -1)\",\n",
    "                       is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha93=dv.add_formula('alpha93',\"Ts_Sum((If(open >= Delay(open,1), 0, Max((open-low),(open - Delay(open,1))))), 20)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha94 = dv.add_formula('alpha94','''Ts_Sum(If(close_adj>Delay(close_adj,1),volume,\n",
    "If(close_adj<Delay(close_adj,1),-volume,0)),30)''',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dv.add_field('turnover')\n",
    "# alpha95 = dv.add_formula('alpha95','StdDev(turnover, 20)',\n",
    "#                   is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha96 = dv.add_formula('alpha96',\"Sma(Sma((close-Ts_Min(low,9))/(Ts_Max(high,9)-Ts_Min(low,9))*100,3,1),3,1)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha97 = dv.add_formula('alpha97', 'StdDev(volume, 10)', add_data = True, is_quarterly = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha98=dv.add_formula('alpha98',\"If((Delta((Ts_Mean(close,100)), 100) / Delay(close, 100)) <= 0.05, (-1 * (close - Ts_Min(close, 100))) , (-1 * Delta(close, 3)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha99 = dv.add_formula('alpha99', \"(-1*Rank(Covariance(Rank(close),Rank(volume),5)))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha100 = dv.add_formula('alpha100', 'StdDev(volume,20)',\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha101 = dv.add_formula('alpha101', \"((Rank(Corr(close,Ts_Sum(Ts_Mean(volume,30),37),15))< Rank(Corr(Rank(((high*0.1) + (vwap*0.9))),Rank(volume),11)))* -1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha102=dv.add_formula('alpha102',\"Sma(Max(volume-Delay(volume,1),0),6,1)/Sma(Abs(volume-Delay(volume,1)),6,1)*100\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "def LOWDAY(A, n):\n",
    "    return (n-1) - A.rolling(window=n).apply(lambda x: np.argsort(x)[n-1]).fillna(method = 'ffill').fillna(method='bfill')\n",
    "alpha103 = dv.add_formula('alpha103',\"((20-LOWDAY(low,20))/20)*100\",\n",
    "        is_quarterly=False, add_data=True,register_funcs={\"LOWDAY\":LOWDAY})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha104 = dv.add_formula('alpha104', \"(-1 * (Delta(Correlation(high, volume, 5), 5) * Rank(StdDev(close, 20))))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha105 =dv.add_formula('alpha105',\"(-1 * Corr(Rank(open), Rank(volume), 10))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha106=dv.add_formula('alpha106', 'close_adj-Delay(close_adj,{})'.format(20), is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha107 = dv.add_formula('alpha107', \"(((-1 * Rank((open - Delay(high, 1)))) * Rank((open - Delay(close, 1)))) * Rank((open - Delay(low, 1))))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha108 = dv.add_formula('alpha108',\"((Rank(high-Ts_Min(high,2)))^(Rank(Correlation(vwap,Ts_Mean(volume,120),6)))*-1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha109=dv.add_formula('alpha109',\"Sma(high-low,10,2)/Sma(Sma(high-low,10,2),10,2)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha110 = dv.add_formula('alpha110', \"Ts_Sum(Max(0,high-Delay(close,1)),20)/Ts_Sum(Max(0,Delay(close,1)-low),20)*100\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha111=dv.add_formula('alpha111',\"Sma(volume*((close-low)-(high-close))/(high-low),11,2)-Sma(volume*((close-low)-(high-close))/(high-low),4,2)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha112=dv.add_formula('alpha112','((Ts_Sum(If((close_adj-Delay(close_adj,1))>0,(close_adj-Delay(close_adj,1)),0),12)-Ts_Sum(If((close_adj-Delay(close_adj,1))<0,Abs(close_adj-Delay(close_adj,1)),0),12))/(Ts_Sum(If((close_adj-Delay(close_adj,1))>0,(close_adj-Delay(close_adj,1)),0),12)+Ts_Sum(If((close_adj-Delay(close_adj,1))<0,Abs(close_adj-Delay(close_adj,1)),0),12))*100)',"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha113 = dv.add_formula('alpha113', \"((-1 * ((Rank((Ts_Sum(Delay(close, 5), 20) / 20)) * Corr(close, volume, 2)) * Rank(Corr(Ts_Sum(close, 5),Ts_Sum(close, 20), 2)))))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha114=dv.add_formula('alpha114',\"((Rank(Delay(((high-low)/(Ts_Sum(close,5)/5)),2))*Rank(Rank(volume)))/(((high-low)/(Ts_Sum(close,5)/5))/(vwap-close)))\",is_quarterly=False,add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha115 = dv.add_formula('alpha115',\"(Rank(Corr(((high*0.9)+(close*0.1)),Ts_Mean(volume,30),10))^Rank(Corr(Ts_Rank(((high+low)/2),4),Ts_Rank(volume,10),7)))\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import talib as ta\n",
    "close = dv.get_ts(\"close_adj\").dropna(how='all', axis=1)\n",
    "Alpha116 = pd.DataFrame({sec_symbol: -ta.LINEARREG_SLOPE(value.values, 20) for sec_symbol, value in close.iteritems()}, index=close.index)\n",
    "dv.append_df(Alpha116,'Alpha116')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "RET = dv.add_formula('RET', 'Return(close_adj, 1)', add_data = True, is_quarterly = False)\n",
    "alpha117 = dv.add_formula('alpha117', '((Ts_Rank(volume, 32))*(1-Ts_Rank(((close_adj + high_adj)-low_adj), 16))*(1-Ts_Rank(RET, 32)))',add_data =True, is_quarterly = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "def SUM(A, n):\n",
    "    return A.rolling(window = n, min_periods = 1, center = False).sum().fillna(method = 'ffill').fillna(method='bfill')\n",
    "\n",
    "alpha118 = dv.add_formula('alpha118',\"SUM(high-open,20)/SUM(open-low,20)*100\" \n",
    "                             , is_quarterly=False, add_data=True,register_funcs={'SUM': SUM})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha119 = dv.add_formula('alpha119',\"(Rank(Decay_linear(Correlation(vwap,Ts_Sum(Ts_Mean(volume,5),26),5),7))-Rank(Decay_linear(Ts_Rank(Ts_Min(Correlation(Rank(open),Rank(Ts_Mean(volume,15)),21),9),7),8)))\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha120 = dv.add_formula('alpha120','Rank(vwap-close)/Rank(vwap+close)',is_quarterly=False,add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha121 = dv.add_formula('alpha121','(Rank(vwap-Ts_Min(vwap,12)))^(Ts_Rank(Correlation(Ts_Rank(vwap,20),Ts_Rank(Ts_Mean(volume,60),2),18),3))',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sma(df, n, m):\n",
    "    a = n / m - 1\n",
    "    r = df.ewm(com=a, axis=0, adjust=False)\n",
    "    return r.mean()\n",
    "alpha122 = dv.add_formula('alpha122',\"(SMA(SMA(SMA(Log(close),13,2),13,2),13,2)-Delay(SMA(SMA(SMA(Log(close),13,2),13,2),13,2),1))/Delay(SMA(SMA(SMA(Log(close),13,2),13,2),13,2),1)\",is_quarterly=False, add_data=True,register_funcs={\"SMA\": sma})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha123 = dv.add_formula('alpha123', \"Rank(Correlation(Ts_Sum((high+low)/2,20),Ts_Sum(Ts_Mean(volume,60),20),9)<Rank(Correlation(low,volume,6)))*-1\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha124 = dv.add_formula('alpha124', '(close_adj-vwap_adj)/Decay_linear(Rank(Ts_Max(close_adj, 30)),2)',is_quarterly=False, add_data=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha125 = dv.add_formula('alpha125',\"Rank(Decay_linear(Correlation((vwap), Ts_Mean(volume,80),17), 20)) / Rank(Decay_linear(Delta(((close * 0.5) + (vwap * 0.5)), 3), 16))\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha126 = dv.add_formula('alpha126', \"(close+high+low)/3\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha127=dv.add_formula('alpha127', '(Ts_Mean(100*(close_adj-Ts_Max(close_adj,12))/(Ts_Max(close_adj,12)))^2)^(1/2)', is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha128 = dv.add_formula('alpha128', \"100-(100/(1+Ts_Sum((If((high+low+close)/3>Delay((high+low+close)/3,1),(high+low+close)/3*volume,0)),14)/Ts_Sum((If((high+low+close)/3<Delay((high+low+close)/3,1),(high+low+close)/3*volume,0)),14)))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha129 = dv.add_formula('alpha129', \"Ts_Sum(If((close-Delay(close,1)<0),Abs(close-Delay(close,1)),0),%s)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "def mean(A, n):\n",
    "    return A.rolling(window = n, min_periods = 1, center = False).mean().fillna(method = 'ffill').fillna(method='bfill')\n",
    "def DECAYLINEAR(A, n):\n",
    "    w = np.arange(n,0,-1)\n",
    "    w = w/w.sum()\n",
    "    return A.rolling(n).apply(lambda x: (x * w).sum()).fillna(method = 'ffill').fillna(method='bfill')\n",
    "alpha130 = dv.add_formula('alpha130',\"(Rank(DECAYLINEAR(Corr(((high+low)/2),mean(volume,40),9),10))/Rank(DECAYLINEAR(Corr(Rank(vwap), Rank(volume), 7),3)))\", is_quarterly=False, add_data=True,register_funcs={\"mean\": mean, \"DECAYLINEAR\": DECAYLINEAR})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha131=dv.add_formula('alpha131',\"(Rank(Delta(vwap, 1))^Ts_Rank(Correlation(close,Ts_Mean(volume,50), 18), 18))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Variable [turnover] is not recognized (it may be wrong),try to fetch from the server...\n",
      "Add field failed. No data_api available. Please specify one in parameter.\n"
     ]
    }
   ],
   "source": [
    "alpha132=dv.add_formula('alpha132',\"Ts_Mean(turnover,20)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha133 = dv.add_formula('alpha133', \"(((20-Ts_Argmax(high,20))/20) * 100 - ((20-Ts_Argmin(low,20))/20) * 100)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha134=dv.add_formula('alpha134','(((close_adj-Delay(close_adj,12))/Delay(close_adj,12))*volume)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha135 = dv.add_formula('alpha135',\"Sma(Delay(close/Delay(close,20),1),20,1)\",\n",
    "                   is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha136 = dv.add_formula('alpha136', \"((-1*Rank(Delay(Return(close,1), 3)))*Correlation(open, volume, 10))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha137 = dv.add_formula('alpha137',\"16*(close-Delay(close,1)+(close-open)/2+Delay(close,1)-Delay(open,1))/If((Abs(high-Delay(close,1))>Abs(low-Delay(close,1))&&Abs(high-Delay(close,1))>Abs(high-Delay(low,1)),Abs(high-Delay(close,1))+Abs(low-Delay(close,1))/2+Abs(Delay(close,1)-Delay(open,1))/4,If(Abs(low-Delay(close,1))>Abs(high-Delay(low,1))&&Abs(low-Delay(close,1))>Abs(high-Delay(close,1)),Abs(low-Delay(close,1))+Abs(high-Delay(close,1))/2+Abs(Delay(close,1)-Delay(open,1))/4,Abs(high-Delay(low,1))+Abs(Delay(close,1)-Delay(open,1))/4)))*Max(Abs(high-Delay(close,1)),Abs(low-Delay(close,1)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha138 = dv.add_formula('alpha138',\"((Rank(Decay_linear(Delta((((low*0.7)+(vwap*0.3))),3),20))-Ts_Rank(Decay_linear(Ts_Rank(Corr(Ts_Rank(low, 8), Ts_Rank(Ts_Mean(volume,60), 17), 5), 19), 16), 7)) * -1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha139 = dv.add_formula('alpha139','-1*Correlation(open, volume, 10)',\n",
    "                  is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha140 = dv.add_formula('alpha140',\"Min(Rank(Decay_linear(((Rank(open_adj)+Rank(low_adj))-Rank(high_adj)+Rank(close_adj),8))),Ts_Rank(Decay_linear(Correlation(Ts_Rank(close_adj, 8), Ts_Rank(Ts_Mean(volume,60), 20), 8), 7), 3))\",is_quarterly=False,add_data = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha141 = dv.add_formula('alpha141', \"Rank(Correlation(Rank(high), Rank(Ts_Mean(volume,15)), 9))* -1\" ,is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha142 = dv.add_formula('alpha142',\"(((-1*Rank(Ts_Rank(close,10)))*Rank(Delta(Delta(close,1),1)))*Rank(Ts_Rank((volume/Ts_Mean(volume,20)),5)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha144 = dv.add_formula('alpha144', \"Ts_Sum(If(((close<Delay(close,1)-1)/CountNans((close-Delay(close,1))^0.5,20)),Abs(close/Delay(close,1)-1)/(close*volume),0),20)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha145 = dv.add_formula('alpha145', \"(Ts_Mean(volume,9)-Ts_Mean(volume,26))/Ts_Mean(volume,12)*100\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha146 = dv.add_formula('alpha146',\"Ts_Mean((close-Delay(close,1))/Delay(close,1)-Sma((close-Delay(close,1))/Delay(close,1),61,2),20)*((close-Delay(close,1))/Delay(close,1)-Sma((close-Delay(close,1))/Delay(close,1),61,2))/Sma((close-Delay(close,1))/Delay(close,1)-((close-Delay(close,1))/Delay(close,1)-Sma((close-Delay(close,1))/Delay(close,1),61,2))^2,60,2)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha147 = dv.add_formula('alpha147', \"Ta('LINEARREG_SLOPE',0,0,0,0,Ts_Mean(close,12),0,12)\", is_quarterly = False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha148=dv.add_formula('alpha148',\"(-1*(Rank(Correlation((open),Ts_Sum(Ts_Mean(volume,60),9),6))<Rank((open - Ts_Min(open,14)))))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha150 = dv.add_formula('alpha150', \"(close+high+low)/3*volume\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha151 = dv.add_formula('alpha151','''Sma(close-Delay(close,20),20,1)''',\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha152 = dv.add_formula(\"alpha152_B\",\"Sma(Ts_Mean(Delay(Sma(Delay(close/Delay(close,9),1),9,1),1),12)-Ts_Mean(Delay(Sma(Delay(close/Delay(close,9),1),9,1),1),26),9,1)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha153 = dv.add_formula('alpha153','(Ts_Mean(close,3)+Ts_Mean(close,6)+Ts_Mean(close,12)+Ts_Mean(close,24))/4',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha154 = dv.add_formula('alpha154','(((vwap- Min(vwap, 16))) < (Correlation(vwap, Ts_Mean(volume,180), 18)))',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha155 = dv.add_formula('alpha155','Sma(volume,13,2)-Sma(volume,27,2)-Sma(Sma(volume,13,2)-Sma(volume,27,2),10,2)',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [],
   "source": [
    "# alpha156 = dv.add_formula(\"alpha156\",\"(Max(Rank(Decay_linear(Delta(vwap, 5), 3)), \n",
    "#         Rank(Decay_linear(((Delta(((open * 0.15) + (low *0.85)),2) / ((open * 0.15) + (low * 0.85))) * -1), 3))) * -1)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha157 = dv.add_formula('alpha157','Ts_Min(Ts_Product(Rank(Rank(Log(Ts_Sum(Ts_Min(Rank(Rank(-1 * Rank(Delta((close - 1), 5)))), 2), 1)))), 1), 5) +Ts_Rank(Delay(-1 * Return(close,1), 6), 5)',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha158 = dv.add_formula('alpha158',\" (high-Sma(close,15,2)-(low-Sma(close,15,2)))/close\"\n",
    "     , is_quarterly = False , add_data = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [],
   "source": [
    "part_1 = dv.add_formula('part_1',\"(close-Ts_Sum(Min(low,Delay(close,1)),6))/Ts_Sum(Max(high,Delay(close,1))-Min(low,Delay(close,1)),6)*12*24\"\n",
    "               , is_quarterly=False, add_data=True)\n",
    "part_2 = dv.add_formula('part_2',\"(close-Ts_Sum(Min(low,Delay(close,1)),12))/Ts_Sum(Max(high,Delay(close,1))-Min(low,Delay(close,1)),12)*6*24\"\n",
    "               , is_quarterly=False, add_data=True)\n",
    "part_3 = dv.add_formula('part_3',\"(close-Ts_Sum(Min(low,Delay(close,1)),24))/Ts_Sum(Max(high,Delay(close,1))-Min(low,Delay(close,1)),24)*6*24\"\n",
    "               , is_quarterly=False, add_data=True)\n",
    "alpha159 =dv.add_formula('alpha159_J', \"(part_1+part_2+part_3)*100/(6*12+6*24+12*24)\"\n",
    "               , is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha160 = dv.add_formula('alpha160', \"Sma(If(close<=Delay(close,1),StdDev(close,20),0),20,1)\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha161=dv.add_formula('alpha161','Ts_Mean(Max(Max((high-low),Abs(Delay(close,1)-high)),Abs(Delay(close,1)-low)),12)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "part = dv.add_formula('part',\"Sma(Max(close-Delay(close,1),0),12,1)/Sma(Abs(close-Delay(close,1)),12,1)\", is_quarterly=False, add_data=True)\n",
    "alpha162 = dv.add_formula('alpha162_J',\"(part*100-Ts_Min(part*100,12))/(Ts_Max(part*100,12)-Ts_Min(part*100,12))\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha163 = dv.add_formula('alpha163','Rank(((((-Return(close,1))*Ts_Mean(volume, 20))*vwap)*(high - close)))',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "condition = dv.add_formula('cond',\"close>Delay(close,1)\"\n",
    "               , is_quarterly=False, add_data=True)\n",
    "result = dv.add_formula('res',\"1/(close-Delay(close,1))\"\n",
    "               , is_quarterly=False, add_data=True)\n",
    "alpha164 = dv.add_formula('alpha164_J',\"Sma((If(cond,res,1)-Ts_Min(If(cond,res,1),12))/(high-low)*100,13,2)\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha166 = dv.add_formula('alpha166',\"-20*Pow((20-1),1.5)*Ts_Sum(close/Delay(close,1)-1-Ts_Mean(close/Delay(close,1)-1,20),20)/((20-1)*(20-2)*Pow(Ts_Sum(Pow(close/Delay(close,1),2),20),1.5))\" , is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha167 = dv.add_formula('alpha167', \"Ts_Sum(If((close_adj-Delay(close_adj,1))>0,close_adj-Delay(close_adj,1),0),12)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha168 = dv.add_formula('alpha168', \"(-1*volume/Ts_Mean(volume,20))\",\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha169 = dv.add_formula('alpha169','Sma(Ts_Mean(Delay(Sma(close-Delay(close,1),9,1),1),12) - Ts_Mean(Delay(Sma(close-Delay(close,1),9,1),1),26),10,1)',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha170 = dv.add_formula('alpha170','((((Rank((1/close))*volume)/Ts_Mean(volume,20))*((high*Rank((high-close)))/(Ts_Sum(high,5)/5)))-Rank((vwap-Delay(vwap,5))))',is_quarterly = False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha171 = dv.add_formula('alpha171',\"((-1 * ((low_adj - close_adj) * (open_adj^5))) / ((close_adj - high_adj) * (close_adj^5)))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [],
   "source": [
    "TR = dv.add_formula('TR', \"Max(Max(high-low,Abs(high-Delay(close,1))),Abs(low-Delay(close,1)))\", is_quarterly=False, add_data=True)\n",
    "LD = dv.add_formula('LD', \"Delay(low,1)-low\", is_quarterly=False, add_data=True)\n",
    "HD = dv.add_formula('HD', \"high-Delay(high,1)\", is_quarterly=False, add_data=True)\n",
    "alpha172 = dv.add_formula('alpha172', \"Ts_Mean(Abs(Ts_Sum(If(LD>0&&LD>HD,LD,0),14)*100/Ts_Sum(TR,14)-Ts_Sum(If(HD>0&&HD>LD,HD,0),14)*100/Ts_Sum(TR,14))/(Ts_Sum(If(LD>0&&LD>HD,LD,0),14)*100/Ts_Sum(TR,14)+Ts_Sum(If(HD>0&&HD>LD,HD,0),14)*100/Ts_Sum(TR,14))*100,6)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "def SMA(A,n,m):\n",
    "        alpha = m/n\n",
    "        return A.ewm(alpha=alpha, adjust=False).mean()\n",
    "\n",
    "alpha173=dv.add_formula('alpha173',\"3*SMA(close,13,2)-2*SMA(SMA(close,13,2),13,2)+SMA(SMA(SMA(Log(close),13,2),13,2),13,2)\",is_quarterly=False,add_data=True,register_funcs={\"SMA\":SMA}) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha174 = dv.add_formula('alpha174_J',\"Sma(If(close>Delay(close,1),StdDev(close,20),0),20,1)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha175 = dv.add_formula('alpha175','Ts_Mean(Max(Max(high-low,Abs(Delay(close,1)-high)),Abs(Delay(close,1)-low)),6)' ,is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha176 = dv.add_formula('alpha176', \"Correlation(Rank(((close - Ts_Min(low, 12)) / (Ts_Max(high, 12) - Ts_Min(low,12)))), Rank(volume), 6)\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha177 =dv.add_formula('alpha177',\"(({}-Ts_Argmax(high,{}))/{})*{}\".format(20,20,20,100),is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha178 = dv.add_formula('alpha178',\"(close-Delay(close,1))/Delay(close,1)*volume\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha179 = dv.add_formula('alpha179_B', \"(Rank(Correlation(vwap, volume, 4)) *Rank(Correlation(Rank(low), Rank(Ts_Mean(volume,50)), 12)))\",is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha180 = dv.add_formula('alpha180_B','(If(Ts_Mean(volume, 20)<volume, ((-Ts_Rank(Abs(Delta(close, 7)), 60))*Sign(Delta(close, 7))), -volume))',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha184 = dv.add_formula('alpha184', 'Rank(Correlation(Delay((open - close), 1), close, 200)) + Rank((open - close))',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha185 = dv.add_formula('alpha185_B', \"Rank((-1 * ((1 - (open / close))^2)))\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Field [HD] is overwritten.\n",
      "Field [LD] is overwritten.\n",
      "Field [TR] is overwritten.\n"
     ]
    }
   ],
   "source": [
    "hd = dv.add_formula('HD', \"high-Delay(high,1)\"\n",
    "                    , is_quarterly=False, add_data=True)\n",
    "ld = dv.add_formula('LD',\"Delay(low,1)-low\"\n",
    "                    , is_quarterly=False, add_data=True)\n",
    "tr = dv.add_formula('TR',\"Max(Max(high-low,Abs(high-Delay(close,1))),Abs(low-Delay(close,1)))\"\n",
    "                    , is_quarterly=False, add_data=True)\n",
    "cond1= dv.add_formula('cond_1', \"LD>0 && LD>HD\"\n",
    "                    , is_quarterly=False, add_data=True)\n",
    "cond2= dv.add_formula('cond_2', \"HD>0 && HD>LD\"\n",
    "                    , is_quarterly=False, add_data=True)\n",
    "res1 = dv.add_formula('res1', \"Ts_Sum(If(cond_1,LD,0),14)*100/Ts_Sum(TR,14)-Ts_Sum(If(cond_2,HD,0),14)*100/Ts_Sum(TR,14)\", is_quarterly=False, add_data=True)\n",
    "res2 = dv.add_formula('res2', \"Ts_Sum(If(cond_1,LD,0),14)*100/Ts_Sum(TR,14)+Ts_Sum(If(cond_2,HD,0),14)*100/Ts_Sum(TR,14)\", is_quarterly=False, add_data=True)\n",
    "\n",
    "alpha186_J = dv.add_formula('alpha186_J',\"(Ts_Mean(Abs(res1)/(res2)*100,6)+Delay(Ts_Mean(Abs(res1)/(res2)*100,6),6))/2\", is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha187 = dv.add_formula('alpha187', \"Ts_Sum(If(open<=Delay(open,1),0,Max((high-open),(open-Delay(open,1)))),20)\",is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha188 = dv.add_formula('alpha188', '''((high-low-Sma(high-low,11,2))/Sma(high-low,11,2))*100''',\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha189 = dv.add_formula('alpha189', 'Ts_Mean(Abs(close-Ts_Mean(close,6)),6)',\n",
    "        is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Field [a] is overwritten.\n"
     ]
    }
   ],
   "source": [
    "a = dv.add_formula('a','close/Delay(close,1)-1',\n",
    "                       is_quarterly=False, add_data=True)\n",
    "b = dv.add_formula('b','(close/Delay(close,19))^(1/20)-1',\n",
    "                       is_quarterly=False, add_data=True)\n",
    "alpha190 = dv.add_formula('alpha190','Log((Ts_Sum(If(a>b,1,0),20)-1)*Ts_Sum(If(a<b,(a-b)^2,0),20)/(Ts_Sum(If(a<b,1,0),20))*Ts_Sum(If(a>b,(a-b)^2,0),20))',is_quarterly=False, add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha191=dv.add_formula('alpha191','((Correlation(Ts_Mean(volume,20),low_adj,5)+(high_adj+low_adj)/2)-close_adj)',is_quarterly=False,add_data=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [],
   "source": [
    "column=['alpha2', 'alpha3', 'alpha4', 'alpha5', 'alpha6', 'alpha7', 'alpha8', 'alpha9', 'alpha10', 'alpha11', 'alpha12', 'alpha13', 'alpha14', 'alpha15', 'alpha16', 'alpha17', 'alpha18', 'alpha19', 'alpha20', 'alpha21', 'alpha22', 'alpha23', 'alpha24', 'alpha25', 'alpha27', 'alpha28', 'alpha29', 'alpha31', 'alpha32', 'alpha33', 'alpha34', 'alpha35', 'alpha36', 'alpha37', 'alpha38', 'alpha39', 'alpha40', 'alpha41', 'alpha42', 'alpha43', 'alpha44', 'alpha45', 'alpha46', 'alpha47', 'alpha48', 'alpha49', 'alpha50', 'alpha51', 'alpha52', 'alpha53', 'alpha54', 'alpha55', 'alpha56', 'alpha58', 'alpha59', 'alpha60', 'alpha61', 'alpha63', 'alpha64', 'alpha65', 'alpha66', 'alpha67', 'alpha68', 'alpha69', 'alpha71', 'alpha72', 'alpha73', 'alpha74', 'alpha75', 'alpha76', 'alpha77', 'alpha78', 'alpha79', 'alpha80', 'alpha81', 'alpha82', 'alpha83', 'alpha84', 'alpha85', 'alpha86', 'alpha87', 'alpha88', 'alpha89', 'alpha90', 'alpha92', 'alpha93', 'alpha94', 'alpha96', 'alpha97', 'alpha98', 'alpha99', 'alpha100', 'alpha101', 'alpha102', 'alpha103', 'alpha104', 'alpha105', 'alpha106', 'alpha107', 'alpha108', 'alpha109', 'alpha110', 'alpha111', 'alpha113', 'alpha114', 'alpha115', 'alpha116', 'alpha117', 'alpha118', 'alpha119', 'alpha120', 'alpha121', 'alpha122', 'alpha123', 'alpha124', 'alpha125', 'alpha126', 'alpha128', 'alpha130', 'alpha131', 'alpha132', 'alpha133', 'alpha134', 'alpha135', 'alpha136', 'alpha137', 'alpha138', 'alpha139', 'alpha140', 'alpha141', 'alpha142', 'alpha143', 'alpha144', 'alpha145', 'alpha146', 'alpha147', 'alpha148', 'alpha149', 'alpha150', 'alpha151', 'alpha152', 'alpha153', 'alpha154', 'alpha155', 'alpha157', 'alpha158', 'alpha159', 'alpha160', 'alpha161', 'alpha162', 'alpha163', 'alpha164', 'alpha165', 'alpha166', 'alpha167', 'alpha168', 'alpha169', 'alpha170', 'alpha171', 'alpha172', 'alpha173', 'alpha174', 'alpha175', 'alpha176', 'alpha177', 'alpha178', 'alpha179', 'alpha180', 'alpha181', 'alpha182', 'alpha183', 'alpha184', 'alpha185', 'alpha186', 'alpha187', 'alpha188', 'alpha189', 'alpha190', 'alpha191','target']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "symbol      000001.SZ  000002.SZ  000008.SZ  000009.SZ  000024.SZ  \\\n",
      "trade_date                                                          \n",
      "20160104    -0.116667        NaN   0.957348   0.142857        NaN   \n",
      "20160105    -0.940476        NaN  -1.467819  -0.967213        NaN   \n",
      "20160106    -0.456583        NaN   0.115023  -0.592109        NaN   \n",
      "20160107     1.527059        NaN   1.205630   1.559322        NaN   \n",
      "20160108    -1.008205        NaN  -1.116621  -1.406061        NaN   \n",
      "20160111     0.728205        NaN   0.799412   1.406061        NaN   \n",
      "20160112    -0.859259        NaN  -0.154921  -1.189189        NaN   \n",
      "20160113     1.175926        NaN   0.563492   1.133634        NaN   \n",
      "20160114    -1.729167        NaN  -1.836828  -1.811111        NaN   \n",
      "20160115     1.601974        NaN   1.463812   1.515789        NaN   \n",
      "20160118    -0.635628        NaN  -0.836806  -1.186160        NaN   \n",
      "20160119    -0.775468        NaN  -0.245066  -0.311064        NaN   \n",
      "20160120     1.066066        NaN   1.442982   1.071982        NaN   \n",
      "20160121     0.555556        NaN  -0.215517   0.669736        NaN   \n",
      "20160122    -1.565217        NaN  -0.973877  -1.652238        NaN   \n",
      "20160125     0.837945        NaN   0.497217   0.980843        NaN   \n",
      "20160126     0.683794        NaN   0.429831   0.777778        NaN   \n",
      "20160127    -1.430206        NaN  -1.549058  -1.217391        NaN   \n",
      "20160128     1.140351        NaN   1.250669   1.058300        NaN   \n",
      "20160129    -1.256410        NaN  -1.113508  -1.642711        NaN   \n",
      "20160201     1.145299        NaN   0.801054   0.575995        NaN   \n",
      "20160202    -0.915556        NaN  -0.793478  -0.123591        NaN   \n",
      "20160203     0.026667        NaN  -0.027778  -0.481111        NaN   \n",
      "20160204     0.166667        NaN   0.700855   0.796026        NaN   \n",
      "20160205     0.833333        NaN  -0.280220   0.906823        NaN   \n",
      "20160215    -1.066667        NaN  -0.210425  -1.487725        NaN   \n",
      "20160216    -0.400000        NaN  -0.138315  -0.016194        NaN   \n",
      "20160217     0.408696        NaN   0.653251   0.203008        NaN   \n",
      "20160218     1.391304        NaN   0.707804   0.989547        NaN   \n",
      "20160219    -0.666667        NaN  -1.200627  -0.498476        NaN   \n",
      "...               ...        ...        ...        ...        ...   \n",
      "20181119    -1.110799  -0.592593   0.190476   1.705882        NaN   \n",
      "20181120     1.449309   1.300000   0.827068  -0.251337        NaN   \n",
      "20181121    -1.011278  -0.322556  -1.684211  -0.086124        NaN   \n",
      "20181122     0.631579   0.036641   1.000000  -0.768421        NaN   \n",
      "20181123     0.662768   0.532307   0.555556   1.096970        NaN   \n",
      "20181126    -0.425926  -0.779268   0.262626  -0.363636        NaN   \n",
      "20181127     0.326087   0.566210  -0.568182  -0.564103        NaN   \n",
      "20181128    -1.426087  -1.333333  -1.068182  -0.519231        NaN   \n",
      "20181129     1.500000   1.608108   1.532468   1.750000        NaN   \n",
      "20181130    -1.900000  -1.248108  -1.142857  -1.809524        NaN   \n",
      "20181203     0.736842   0.168000   0.228571   0.952381        NaN   \n",
      "20181204    -0.070175   0.700571   0.311111  -0.767857        NaN   \n",
      "20181205     0.424242  -0.389862  -0.611111   0.095588        NaN   \n",
      "20181206     0.623377   0.459536   1.500000   1.243697        NaN   \n",
      "20181207     0.119048   0.099015  -0.500000  -0.114286        NaN   \n",
      "20181210    -0.404762   0.312885   0.100000  -0.369231        NaN   \n",
      "20181211    -0.761905  -1.691453  -1.200000  -0.119658        NaN   \n",
      "20181212     0.666667   1.344945   0.400000  -0.361111        NaN   \n",
      "20181213    -0.690476  -0.672048  -0.211765  -0.134615        NaN   \n",
      "20181214     1.251880   0.933411   1.286765   1.230769        NaN   \n",
      "20181217    -1.546911  -1.057099  -0.056818  -1.493213        NaN   \n",
      "20181218     1.470356   1.127337  -1.018182   0.416290        NaN   \n",
      "20181219    -0.103896  -0.184600   0.950000   1.048951        NaN   \n",
      "20181220    -0.184874  -0.387043  -1.083333  -1.090909        NaN   \n",
      "20181221    -0.178060   0.133161  -0.333333   0.772727        NaN   \n",
      "20181224    -0.922780  -0.723423   0.275362  -1.250000        NaN   \n",
      "20181225     0.389610   0.061905   0.057971   0.653226        NaN   \n",
      "20181226     0.781818   0.304762   1.066667  -0.069892        NaN   \n",
      "20181227     0.400000   1.100000  -0.209524   1.166667        NaN   \n",
      "20181228    -0.933333  -0.526316  -0.523810  -0.222222        NaN   \n",
      "\n",
      "symbol         000027.SZ  000039.SZ  000046.SZ  000060.SZ  000061.SZ  \\\n",
      "trade_date                                                             \n",
      "20160104    1.700680e-01   0.045221   0.111137   0.228571   0.269841   \n",
      "20160105   -1.214886e+00  -1.197073  -1.243776  -1.226891  -1.200000   \n",
      "20160106   -4.789916e-01  -0.682336  -0.172650  -0.407892  -0.175000   \n",
      "20160107    1.663653e+00   1.787942   1.415561   1.616091   1.375000   \n",
      "20160108   -1.273691e+00  -0.955774  -1.019444  -1.647975  -1.236842   \n",
      "20160111    1.018769e+00   1.090909  -0.615739   1.557823   0.754699   \n",
      "20160112   -8.944444e-01  -1.214286   1.075099  -0.459338  -1.107601   \n",
      "20160113    1.200000e+00   1.076355   0.363636   0.545710   1.552707   \n",
      "20160114   -1.952381e+00  -1.582069  -1.624242  -1.922482  -1.769415   \n",
      "20160115    1.812846e+00   1.281404   1.321212   1.716383   1.561554   \n",
      "20160118   -1.315011e+00  -0.848760  -1.035191  -0.953247  -1.360365   \n",
      "20160119   -3.073593e-01  -0.339017  -0.230676  -0.459973  -0.201188   \n",
      "20160120    3.619048e-01   1.017678   1.600794   1.248934   1.277716   \n",
      "20160121    1.400000e+00   0.584004  -0.254590   0.392857   0.528736   \n",
      "20160122   -1.066667e+00  -1.371535  -0.778127  -1.636364  -1.192308   \n",
      "20160125    5.333333e-01   0.815581   0.363243   0.480808  -0.334008   \n",
      "20160126    5.047619e-01   0.580645  -0.329302   1.155556   0.980861   \n",
      "20160127   -8.857143e-01  -1.105691  -0.280059  -1.272727  -1.454545   \n",
      "20160128    4.527473e-01   0.873133  -0.310638   1.066542   1.476190   \n",
      "20160129   -1.174825e+00  -1.068647   0.365217  -1.353136  -0.928571   \n",
      "20160201    7.942584e-01   0.537568   1.071146   0.388590  -0.252537   \n",
      "20160202   -8.502024e-01  -0.982395  -0.952153  -0.579268   0.063127   \n",
      "20160203   -6.959707e-02   0.044539  -0.037152   0.216667  -0.191542   \n",
      "20160204    1.097308e-01   0.381493   0.625668  -0.466667   0.787879   \n",
      "20160205    1.118841e+00   1.059130   0.727273   1.861111   1.045455   \n",
      "20160215   -1.109524e+00  -0.975494  -1.500000  -1.361111  -1.308642   \n",
      "20160216   -1.171429e-01  -0.509668  -0.233333        NaN  -0.387010   \n",
      "20160217    3.117241e-01  -0.191468   0.579487        NaN   0.251208   \n",
      "20160218    6.896552e-01   1.253956   0.953846   0.745098   1.323232   \n",
      "20160219   -2.413793e-01  -0.205345  -0.627586  -0.500000  -0.483439   \n",
      "...                  ...        ...        ...        ...        ...   \n",
      "20181119    9.885057e-01  -0.356364   0.333333  -1.250000  -0.608696   \n",
      "20181120    3.137255e-01   1.490022   0.904762   1.833333   1.733333   \n",
      "20181121   -1.404635e+00  -1.308204  -0.529762  -1.833333  -1.457471   \n",
      "20181122    1.007576e+00   0.866310   0.280172   1.000000   0.801061   \n",
      "20181123    7.500000e-01   0.254902   0.290774   1.000000   0.808791   \n",
      "20181126   -1.000000e+00  -0.066667  -1.240064  -0.000000  -1.385714   \n",
      "20181127    6.470588e-01  -0.475000   1.112299  -0.666667   1.136364   \n",
      "20181128   -1.424837e+00  -0.603261  -1.618182  -1.166667  -1.531100   \n",
      "20181129    1.527778e+00   1.393154   1.133333   1.651515   1.811404   \n",
      "20181130   -1.500000e+00  -1.704367  -0.933333  -1.818182  -1.516667   \n",
      "20181203    7.500000e-01   0.932331   0.533333   1.200000   0.400000   \n",
      "20181204   -7.500000e-01  -1.017857  -0.647619  -0.533333   0.109091   \n",
      "20181205    6.388889e-01   0.995000   0.089286   0.333333   0.257576   \n",
      "20181206   -3.174603e-02   0.680000   1.491667   0.777778   0.433333   \n",
      "20181207   -8.571429e-01  -1.184615  -0.977778  -0.577778  -1.418182   \n",
      "20181210    5.714286e-01   1.202797  -0.138889  -0.000000   1.644269   \n",
      "20181211    4.952381e-01  -1.151515  -0.204545  -0.533333  -0.968944   \n",
      "20181212   -6.666667e-01   0.476190   1.090909   0.333333   0.031746   \n",
      "20181213    7.111111e-01  -0.857143  -0.636364  -0.555556  -0.581197   \n",
      "20181214    4.888889e-01   1.428571   0.238095   1.555556   0.663736   \n",
      "20181217   -4.333333e-01  -0.844720  -0.038095  -1.500000  -0.615873   \n",
      "20181218   -8.137255e-01  -0.019565  -0.057143   0.500000   0.844444   \n",
      "20181219    1.397059e+00   1.150000   0.412698   1.000000   0.800000   \n",
      "20181220   -1.416667e+00  -0.823529  -0.088889  -1.500000  -0.666667   \n",
      "20181221    1.666667e-01   0.442577  -1.200000   0.833333   0.405797   \n",
      "20181224    3.571429e-01  -1.119048   1.233333  -1.047619  -1.508361   \n",
      "20181225   -5.714286e-02   0.242857  -0.630435   0.441558   0.475113   \n",
      "20181226    5.714286e-02   0.923810   0.019324   0.939394   0.760784   \n",
      "20181227    1.448841e-14   0.156863   0.993464   0.083333   0.442424   \n",
      "20181228    1.142857e+00  -1.301790  -0.993464  -0.150000  -1.051948   \n",
      "\n",
      "symbol        ...      603160.SH  603259.SH  603260.SH  603288.SH  603799.SH  \\\n",
      "trade_date    ...                                                              \n",
      "20160104      ...            NaN        NaN        NaN  -0.071707   0.072703   \n",
      "20160105      ...            NaN        NaN        NaN  -1.485663  -0.590191   \n",
      "20160106      ...            NaN        NaN        NaN   0.478774  -1.036823   \n",
      "20160107      ...            NaN        NaN        NaN   1.075667   1.671958   \n",
      "20160108      ...            NaN        NaN        NaN  -0.999537  -1.595308   \n",
      "20160111      ...            NaN        NaN        NaN   1.025607   1.119471   \n",
      "20160112      ...            NaN        NaN        NaN  -1.070968  -0.626204   \n",
      "20160113      ...            NaN        NaN        NaN   0.960000   0.660180   \n",
      "20160114      ...            NaN        NaN        NaN  -1.448172  -1.493099   \n",
      "20160115      ...            NaN        NaN        NaN   1.310394   1.496184   \n",
      "20160118      ...            NaN        NaN        NaN  -1.112155  -1.022217   \n",
      "20160119      ...            NaN        NaN        NaN  -0.317085  -0.180386   \n",
      "20160120      ...            NaN        NaN        NaN   1.273684   1.543340   \n",
      "20160121      ...            NaN        NaN        NaN   0.408333   0.085918   \n",
      "20160122      ...            NaN        NaN        NaN  -0.360714  -0.885838   \n",
      "20160125      ...            NaN        NaN        NaN  -0.075689  -0.027967   \n",
      "20160126      ...            NaN        NaN        NaN  -0.198830   0.925926   \n",
      "20160127      ...            NaN        NaN        NaN  -0.168338  -1.054545   \n",
      "20160128      ...            NaN        NaN        NaN   0.632275   0.542149   \n",
      "20160129      ...            NaN        NaN        NaN  -1.262145  -1.308499   \n",
      "20160201      ...            NaN        NaN        NaN   0.246966   1.292594   \n",
      "20160202      ...            NaN        NaN        NaN  -0.322933  -1.209793   \n",
      "20160203      ...            NaN        NaN        NaN   0.286583   0.271429   \n",
      "20160204      ...            NaN        NaN        NaN   0.418249  -0.533333   \n",
      "20160205      ...            NaN        NaN        NaN   0.633281   1.928571   \n",
      "20160215      ...            NaN        NaN        NaN  -0.960847  -1.264935   \n",
      "20160216      ...            NaN        NaN        NaN  -0.176190  -0.395595   \n",
      "20160217      ...            NaN        NaN        NaN   0.322222  -0.049291   \n",
      "20160218      ...            NaN        NaN        NaN   0.732733   1.246899   \n",
      "20160219      ...            NaN        NaN        NaN  -1.226017  -0.385649   \n",
      "...           ...            ...        ...        ...        ...        ...   \n",
      "20181119      ...       0.012715   0.020389  -0.728112  -1.034286  -0.691196   \n",
      "20181120      ...       1.540797   0.181292   0.537226   1.633826   1.473569   \n",
      "20181121      ...      -1.122482  -1.421029  -0.533707  -1.765694  -1.055970   \n",
      "20181122      ...       0.379058   1.348806   0.480952   0.413083   1.224490   \n",
      "20181123      ...       0.987013   0.294021   0.680638   1.012018  -0.160645   \n",
      "20181126      ...      -0.047493  -0.494520  -0.709004  -0.130128  -0.109196   \n",
      "20181127      ...      -1.028137  -0.344495   0.860284   0.132576  -0.080808   \n",
      "20181128      ...      -0.526360  -0.964743  -1.464321  -1.493964  -1.396149   \n",
      "20181129      ...       0.894025   1.834061   1.560976   1.900298   1.749655   \n",
      "20181130      ...      -0.387780  -1.468750  -1.772727  -0.722030  -1.489344   \n",
      "20181203      ...      -0.315108  -0.322295   0.381423  -1.067025   0.411162   \n",
      "20181204      ...      -0.240238  -0.066733   0.263099   0.105418  -0.269623   \n",
      "20181205      ...       0.256354   0.401467  -0.362241   0.345160  -0.074239   \n",
      "20181206      ...       1.055530   1.260311   0.697342   1.098410   0.162044   \n",
      "20181207      ...      -1.284555  -1.169591   0.301875  -0.317496   1.106897   \n",
      "20181210      ...       0.044815   0.743369  -0.101365  -0.266531   0.279215   \n",
      "20181211      ...       0.293233  -0.607286  -0.060469  -1.163636  -1.313214   \n",
      "20181212      ...      -0.105232   0.109508   0.243970   0.622222   0.892320   \n",
      "20181213      ...      -0.374291  -0.260753  -1.014638  -0.501674  -1.019763   \n",
      "20181214      ...       1.155965   1.249440   1.141376   1.208442   1.336124   \n",
      "20181217      ...      -0.092185  -0.717849  -0.666365  -0.803851  -1.659357   \n",
      "20181218      ...       0.048231  -0.784641   0.117035   0.156179   0.130719   \n",
      "20181219      ...      -0.116727   1.255231   0.806992   0.839007   1.380392   \n",
      "20181220      ...      -1.066585  -0.672276  -1.922677  -0.690450  -0.301235   \n",
      "20181221      ...       0.785256  -0.282486   0.792439   0.319492   0.216550   \n",
      "20181224      ...      -0.263481  -0.083333  -0.771900  -0.872771  -1.248649   \n",
      "20181225      ...       1.281705  -0.333333   0.500600   0.754654   0.493855   \n",
      "20181226      ...      -0.026402   0.906627   0.345148   0.653598   0.984933   \n",
      "20181227      ...      -0.902079   0.802557   1.042865  -1.193266   0.040675   \n",
      "20181228      ...      -0.566917  -1.012755  -0.548450  -0.491582  -1.164361   \n",
      "\n",
      "symbol      603833.SH  603858.SH  603885.SH  603986.SH  603993.SH  \n",
      "trade_date                                                         \n",
      "20160104          NaN        NaN   0.087591        NaN   0.289855  \n",
      "20160105          NaN        NaN  -0.844828        NaN  -1.432712  \n",
      "20160106          NaN        NaN  -0.162924        NaN  -0.523810  \n",
      "20160107          NaN        NaN   0.999521        NaN   2.000000  \n",
      "20160108          NaN        NaN  -1.627590        NaN  -1.421053  \n",
      "20160111          NaN        NaN   0.829264        NaN   1.247140  \n",
      "20160112          NaN        NaN  -0.544794        NaN  -1.159420  \n",
      "20160113          NaN        NaN   1.185938        NaN   0.583333  \n",
      "20160114          NaN        NaN  -1.653591        NaN  -0.886364  \n",
      "20160115          NaN        NaN   1.453620        NaN   1.160173  \n",
      "20160118          NaN        NaN  -1.025920        NaN  -0.857143  \n",
      "20160119          NaN        NaN  -0.361942        NaN  -0.666667  \n",
      "20160120          NaN        NaN   0.633981        NaN   1.500000  \n",
      "20160121          NaN        NaN   1.088963        NaN   0.375000  \n",
      "20160122          NaN        NaN  -1.231602        NaN  -1.041667  \n",
      "20160125          NaN        NaN   0.610219        NaN   0.416667  \n",
      "20160126          NaN        NaN   0.181097        NaN   0.573529  \n",
      "20160127          NaN        NaN  -0.764967        NaN  -0.852101  \n",
      "20160128          NaN        NaN   1.106843        NaN   0.846753  \n",
      "20160129          NaN        NaN  -1.295016        NaN  -1.048951  \n",
      "20160201          NaN        NaN   0.688686        NaN   0.503497  \n",
      "20160202          NaN        NaN  -0.833139        NaN  -0.828283  \n",
      "20160203          NaN        NaN  -0.061448        NaN   0.170940  \n",
      "20160204          NaN        NaN   0.421576        NaN   0.080268  \n",
      "20160205          NaN        NaN   0.541387        NaN   1.122530  \n",
      "20160215          NaN        NaN  -0.982736        NaN  -1.406417  \n",
      "20160216          NaN        NaN  -0.218729        NaN   0.121569  \n",
      "20160217          NaN        NaN   0.527926        NaN  -0.200000  \n",
      "20160218          NaN        NaN   1.217129        NaN   0.695238  \n",
      "20160219          NaN        NaN  -0.818100        NaN   0.221429  \n",
      "...               ...        ...        ...        ...        ...  \n",
      "20181119     0.718370  -1.076068  -0.579060   0.389811  -0.571429  \n",
      "20181120     0.402269   1.539560   0.515873   0.753163   1.120879  \n",
      "20181121    -1.338474  -1.740260  -0.609307  -1.689931  -1.538462  \n",
      "20181122     1.345783   0.887879  -0.002819   1.790377   1.596154  \n",
      "20181123    -0.592035   0.243590   0.657364   0.107644   0.076087  \n",
      "20181126     0.320511  -0.542229  -0.139394  -0.291916  -0.007905  \n",
      "20181127    -0.070958   0.499349  -0.779904  -1.153436  -1.068182  \n",
      "20181128    -0.940011  -0.868189  -0.947368   0.126570  -0.750000  \n",
      "20181129     1.213226   1.612407   1.963636   1.391011   1.636364  \n",
      "20181130    -1.128324  -1.484754  -1.809790  -1.551858  -1.064935  \n",
      "20181203     0.123112  -0.383917   1.346154   0.269780   0.428571  \n",
      "20181204    -0.229779   0.219823  -1.034884   0.949890  -0.333333  \n",
      "20181205    -0.072281   0.262425   0.754396  -0.772748  -0.121212  \n",
      "20181206     0.995341   1.236120   0.416851   0.566556   1.168831  \n",
      "20181207    -0.679992  -0.135649  -0.636364  -0.259450  -0.285714  \n",
      "20181210     0.862820   0.263248   0.500000  -0.463622   0.571429  \n",
      "20181211    -1.501396  -0.931165  -0.441176   0.308902  -1.666667  \n",
      "20181212     0.748841   0.522780   0.007843   0.954861  -0.047619  \n",
      "20181213    -0.454775  -0.867925  -0.758974  -1.254469   0.114286  \n",
      "20181214     1.608108   1.320755   1.538462   1.051916   1.418182  \n",
      "20181217    -0.104530  -1.801980  -0.453297  -0.732259  -1.651515  \n",
      "20181218    -1.799580   0.801980  -0.080357   0.285489   0.633333  \n",
      "20181219     1.628599   0.777778   0.416314   0.262383   0.914286  \n",
      "20181220    -0.514525  -1.261649  -1.373258  -0.956383  -0.380952  \n",
      "20181221    -0.357333   0.788219   0.022823   0.191699   0.380952  \n",
      "20181224    -0.522665  -0.465638   0.008718  -0.524759  -0.464286  \n",
      "20181225     0.870034  -0.495275  -0.116827  -0.186505  -0.983333  \n",
      "20181226     0.679310   0.284017   0.242550   1.797623   1.733333  \n",
      "20181227    -0.393596   1.372549   0.087179  -0.058492  -0.111111  \n",
      "20181228     0.288645  -1.071429  -0.048276  -1.309565  -0.460317  \n",
      "\n",
      "[731 rows x 456 columns]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([20160104, 20160105, 20160106, 20160107, 20160108, 20160111,\n",
       "       20160112, 20160113, 20160114, 20160115, 20160118, 20160119,\n",
       "       20160120, 20160121, 20160122, 20160125, 20160126, 20160127,\n",
       "       20160128, 20160129, 20160201, 20160202, 20160203, 20160204,\n",
       "       20160205, 20160215, 20160216, 20160217, 20160218, 20160219,\n",
       "       20160222, 20160223, 20160224, 20160225, 20160226, 20160229,\n",
       "       20160301, 20160302, 20160303, 20160304, 20160307, 20160308,\n",
       "       20160309, 20160310, 20160311, 20160314, 20160315, 20160316,\n",
       "       20160317, 20160318, 20160321, 20160322, 20160323, 20160324,\n",
       "       20160325, 20160328, 20160329, 20160330, 20160331, 20160401,\n",
       "       20160405, 20160406, 20160407, 20160408, 20160411, 20160412,\n",
       "       20160413, 20160414, 20160415, 20160418, 20160419, 20160420,\n",
       "       20160421, 20160422, 20160425, 20160426, 20160427, 20160428,\n",
       "       20160429, 20160503, 20160504, 20160505, 20160506, 20160509,\n",
       "       20160510, 20160511, 20160512, 20160513, 20160516, 20160517,\n",
       "       20160518, 20160519, 20160520, 20160523, 20160524, 20160525,\n",
       "       20160526, 20160527, 20160530, 20160531, 20160601, 20160602,\n",
       "       20160603, 20160606, 20160607, 20160608, 20160613, 20160614,\n",
       "       20160615, 20160616, 20160617, 20160620, 20160621, 20160622,\n",
       "       20160623, 20160624, 20160627, 20160628, 20160629, 20160630,\n",
       "       20160701, 20160704, 20160705, 20160706, 20160707, 20160708,\n",
       "       20160711, 20160712, 20160713, 20160714, 20160715, 20160718,\n",
       "       20160719, 20160720, 20160721, 20160722, 20160725, 20160726,\n",
       "       20160727, 20160728, 20160729, 20160801, 20160802, 20160803,\n",
       "       20160804, 20160805, 20160808, 20160809, 20160810, 20160811,\n",
       "       20160812, 20160815, 20160816, 20160817, 20160818, 20160819,\n",
       "       20160822, 20160823, 20160824, 20160825, 20160826, 20160829,\n",
       "       20160830, 20160831, 20160901, 20160902, 20160905, 20160906,\n",
       "       20160907, 20160908, 20160909, 20160912, 20160913, 20160914,\n",
       "       20160919, 20160920, 20160921, 20160922, 20160923, 20160926,\n",
       "       20160927, 20160928, 20160929, 20160930, 20161010, 20161011,\n",
       "       20161012, 20161013, 20161014, 20161017, 20161018, 20161019,\n",
       "       20161020, 20161021, 20161024, 20161025, 20161026, 20161027,\n",
       "       20161028, 20161031, 20161101, 20161102, 20161103, 20161104,\n",
       "       20161107, 20161108, 20161109, 20161110, 20161111, 20161114,\n",
       "       20161115, 20161116, 20161117, 20161118, 20161121, 20161122,\n",
       "       20161123, 20161124, 20161125, 20161128, 20161129, 20161130,\n",
       "       20161201, 20161202, 20161205, 20161206, 20161207, 20161208,\n",
       "       20161209, 20161212, 20161213, 20161214, 20161215, 20161216,\n",
       "       20161219, 20161220, 20161221, 20161222, 20161223, 20161226,\n",
       "       20161227, 20161228, 20161229, 20161230, 20170103, 20170104,\n",
       "       20170105, 20170106, 20170109, 20170110, 20170111, 20170112,\n",
       "       20170113, 20170116, 20170117, 20170118, 20170119, 20170120,\n",
       "       20170123, 20170124, 20170125, 20170126, 20170203, 20170206,\n",
       "       20170207, 20170208, 20170209, 20170210, 20170213, 20170214,\n",
       "       20170215, 20170216, 20170217, 20170220, 20170221, 20170222,\n",
       "       20170223, 20170224, 20170227, 20170228, 20170301, 20170302,\n",
       "       20170303, 20170306, 20170307, 20170308, 20170309, 20170310,\n",
       "       20170313, 20170314, 20170315, 20170316, 20170317, 20170320,\n",
       "       20170321, 20170322, 20170323, 20170324, 20170327, 20170328,\n",
       "       20170329, 20170330, 20170331, 20170405, 20170406, 20170407,\n",
       "       20170410, 20170411, 20170412, 20170413, 20170414, 20170417,\n",
       "       20170418, 20170419, 20170420, 20170421, 20170424, 20170425,\n",
       "       20170426, 20170427, 20170428, 20170502, 20170503, 20170504,\n",
       "       20170505, 20170508, 20170509, 20170510, 20170511, 20170512,\n",
       "       20170515, 20170516, 20170517, 20170518, 20170519, 20170522,\n",
       "       20170523, 20170524, 20170525, 20170526, 20170531, 20170601,\n",
       "       20170602, 20170605, 20170606, 20170607, 20170608, 20170609,\n",
       "       20170612, 20170613, 20170614, 20170615, 20170616, 20170619,\n",
       "       20170620, 20170621, 20170622, 20170623, 20170626, 20170627,\n",
       "       20170628, 20170629, 20170630, 20170703, 20170704, 20170705,\n",
       "       20170706, 20170707, 20170710, 20170711, 20170712, 20170713,\n",
       "       20170714, 20170717, 20170718, 20170719, 20170720, 20170721,\n",
       "       20170724, 20170725, 20170726, 20170727, 20170728, 20170731,\n",
       "       20170801, 20170802, 20170803, 20170804, 20170807, 20170808,\n",
       "       20170809, 20170810, 20170811, 20170814, 20170815, 20170816,\n",
       "       20170817, 20170818, 20170821, 20170822, 20170823, 20170824,\n",
       "       20170825, 20170828, 20170829, 20170830, 20170831, 20170901,\n",
       "       20170904, 20170905, 20170906, 20170907, 20170908, 20170911,\n",
       "       20170912, 20170913, 20170914, 20170915, 20170918, 20170919,\n",
       "       20170920, 20170921, 20170922, 20170925, 20170926, 20170927,\n",
       "       20170928, 20170929, 20171009, 20171010, 20171011, 20171012,\n",
       "       20171013, 20171016, 20171017, 20171018, 20171019, 20171020,\n",
       "       20171023, 20171024, 20171025, 20171026, 20171027, 20171030,\n",
       "       20171031, 20171101, 20171102, 20171103, 20171106, 20171107,\n",
       "       20171108, 20171109, 20171110, 20171113, 20171114, 20171115,\n",
       "       20171116, 20171117, 20171120, 20171121, 20171122, 20171123,\n",
       "       20171124, 20171127, 20171128, 20171129, 20171130, 20171201,\n",
       "       20171204, 20171205, 20171206, 20171207, 20171208, 20171211,\n",
       "       20171212, 20171213, 20171214, 20171215, 20171218, 20171219,\n",
       "       20171220, 20171221, 20171222, 20171225, 20171226, 20171227,\n",
       "       20171228, 20171229, 20180102, 20180103, 20180104, 20180105,\n",
       "       20180108, 20180109, 20180110, 20180111, 20180112, 20180115,\n",
       "       20180116, 20180117, 20180118, 20180119, 20180122, 20180123,\n",
       "       20180124, 20180125, 20180126, 20180129, 20180130, 20180131,\n",
       "       20180201, 20180202, 20180205, 20180206, 20180207, 20180208,\n",
       "       20180209, 20180212, 20180213, 20180214, 20180222, 20180223,\n",
       "       20180226, 20180227, 20180228, 20180301, 20180302, 20180305,\n",
       "       20180306, 20180307, 20180308, 20180309, 20180312, 20180313,\n",
       "       20180314, 20180315, 20180316, 20180319, 20180320, 20180321,\n",
       "       20180322, 20180323, 20180326, 20180327, 20180328, 20180329,\n",
       "       20180330, 20180402, 20180403, 20180404, 20180409, 20180410,\n",
       "       20180411, 20180412, 20180413, 20180416, 20180417, 20180418,\n",
       "       20180419, 20180420, 20180423, 20180424, 20180425, 20180426,\n",
       "       20180427, 20180502, 20180503, 20180504, 20180507, 20180508,\n",
       "       20180509, 20180510, 20180511, 20180514, 20180515, 20180516,\n",
       "       20180517, 20180518, 20180521, 20180522, 20180523, 20180524,\n",
       "       20180525, 20180528, 20180529, 20180530, 20180531, 20180601,\n",
       "       20180604, 20180605, 20180606, 20180607, 20180608, 20180611,\n",
       "       20180612, 20180613, 20180614, 20180615, 20180619, 20180620,\n",
       "       20180621, 20180622, 20180625, 20180626, 20180627, 20180628,\n",
       "       20180629, 20180702, 20180703, 20180704, 20180705, 20180706,\n",
       "       20180709, 20180710, 20180711, 20180712, 20180713, 20180716,\n",
       "       20180717, 20180718, 20180719, 20180720, 20180723, 20180724,\n",
       "       20180725, 20180726, 20180727, 20180730, 20180731, 20180801,\n",
       "       20180802, 20180803, 20180806, 20180807, 20180808, 20180809,\n",
       "       20180810, 20180813, 20180814, 20180815, 20180816, 20180817,\n",
       "       20180820, 20180821, 20180822, 20180823, 20180824, 20180827,\n",
       "       20180828, 20180829, 20180830, 20180831, 20180903, 20180904,\n",
       "       20180905, 20180906, 20180907, 20180910, 20180911, 20180912,\n",
       "       20180913, 20180914, 20180917, 20180918, 20180919, 20180920,\n",
       "       20180921, 20180925, 20180926, 20180927, 20180928, 20181008,\n",
       "       20181009, 20181010, 20181011, 20181012, 20181015, 20181016,\n",
       "       20181017, 20181018, 20181019, 20181022, 20181023, 20181024,\n",
       "       20181025, 20181026, 20181029, 20181030, 20181031, 20181101,\n",
       "       20181102, 20181105, 20181106, 20181107, 20181108, 20181109,\n",
       "       20181112, 20181113, 20181114, 20181115, 20181116, 20181119,\n",
       "       20181120, 20181121, 20181122, 20181123, 20181126, 20181127,\n",
       "       20181128, 20181129, 20181130, 20181203, 20181204, 20181205,\n",
       "       20181206, 20181207, 20181210, 20181211, 20181212, 20181213,\n",
       "       20181214, 20181217, 20181218, 20181219, 20181220, 20181221,\n",
       "       20181224, 20181225, 20181226, 20181227, 20181228], dtype=int64)"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=dv.get_ts(\"alpha2\")\n",
    "print(data)\n",
    "date=dv.get_ts(\"alpha2\").index.values\n",
    "date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in column:\n",
    "    data=dv.get_ts('%s'%i)\n",
    "    data.to_csv('%s.csv'%i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
